package com.wangtao.firstapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.wangtao.firstapp.R;

/**
 * 原为原创文章指南图片二级页面
 * 现用来加载显示网址
 * Created by lanouhn on 16/9/2.
 */
public class ArticleGuidePicture extends AppCompatActivity {
    private WebView webview;
    private ImageView iv_title_back_articleguide;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_articleguidepicture);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        webview = (WebView) findViewById(R.id.webview);
        iv_title_back_articleguide = (ImageView) findViewById(R.id.iv_title_back_articleguide);
    }

    private void initData() {
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        WebSettings webSettings = webview.getSettings();
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setUseWideViewPort(true);
        webSettings.setJavaScriptEnabled(true);
        webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
//        webview.loadUrl(url);
        webview = (WebView) findViewById(R.id.webview);
        //WebView加载web资源
        webview.loadUrl(url);
        //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
        webview.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
    }

    private void initEvent() {
        iv_title_back_articleguide.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
